package com.itheima.web.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.domain.Movies;
import com.itheima.service.MoviesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController //@Controller+@ResponseBody
@RequestMapping("/movies")
public class MoviesController {

    @Autowired
    private MoviesService moviesService;

    //分页查询影视列表数据
    @GetMapping("/findByPage")
    public PageInfo<Movies> findByPage(@RequestParam(value = "pageNum",defaultValue = "1")
                                       Integer pageNum,
                                       @RequestParam(value = "pageSize",defaultValue = "5")
                                       Integer pageSize,Integer cid,String keyword){
        PageInfo<Movies> pageInfo = moviesService.findByPage(pageNum, pageSize,cid,keyword);
        return pageInfo;
    }
    //保存影视数据
    @PostMapping("/save")
    public String save(@RequestBody Movies movies){
        moviesService.save(movies);
        return "ok";
    }

    //基于id查询影视信息
    @GetMapping("/findById")
    public Movies findById(Integer id){
        return moviesService.findById(id);
    }

    //基于id删除影视 信息
    @DeleteMapping("/deleteById")
    public String deleteById(Integer id){
        moviesService.deleteById(id);
        return "ok";
    }

    //批量删除影视信息
    @DeleteMapping("/deleteBatch")
    public String deleteBatch(Integer[] ids){
        moviesService.deleteBatch(ids);
        return "ok";
    }
}
